package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.ReportFeedbackViewHolder;
import com.molyfun.parents.rest.RestClient;
import com.molyfun.parents.rest.bean.ReportPlanFeedbackListResponse;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 报告查看反馈列表
 */
public class FeedbackFactory extends AbstractListFactory<ReportPlanFeedbackListResponse.ReportFeedbackBean> {

    private String mTrainingid;

    public FeedbackFactory(String trainingid){
        this.mTrainingid = trainingid;
    }

    @Override
    public int getTitle() {
        return R.string.activity_title_view_feedback;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {

        Call<ReportPlanFeedbackListResponse> call = MFPApplication.getInstance().getRestClient().getTrainingFeedbackList(mTrainingid, pageNum, RestClient.DEFAULT_PAGE_SIZE);
        call.enqueue(new Callback<ReportPlanFeedbackListResponse>() {
            @Override
            public void onResponse(Call<ReportPlanFeedbackListResponse> call, Response<ReportPlanFeedbackListResponse> response) {
                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
                    responseCallback.onResponse(response.body().getData().getRecords());
                }
            }

            @Override
            public void onFailure(Call<ReportPlanFeedbackListResponse> call, Throwable t) {
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new ReportFeedbackViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_report_plan_feedback_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final ReportPlanFeedbackListResponse.ReportFeedbackBean topicBriefBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {
        ReportFeedbackViewHolder reportFeedbackViewHolder = (ReportFeedbackViewHolder)holder;
        reportFeedbackViewHolder.mTrainingGoal.setText(topicBriefBean.getTeachingpurpose());
        reportFeedbackViewHolder.mAdvantagesAndDisadvantages.setText(topicBriefBean.getShortcoming());
        reportFeedbackViewHolder.mClassRoomPerformance.setText(topicBriefBean.getClassroomperformance());
        if(position == (totalSize - 1)){
            reportFeedbackViewHolder.mLine.setVisibility(View.GONE);
        }else{
            reportFeedbackViewHolder.mLine.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void deleteData(String id,final int position) {
    }

}
